﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CopsBanditsUI.OfficerCellStates {
    import flash.events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Modules.workers.*;
    import Modules.bandits.*;
    import Display.*;
    import Display.CopsBanditsUI.*;
    import flash.text.*;
    import Display.aswingui.*;

    public class SleepingOfficerState extends GenericOfficerState {

        public function SleepingOfficerState(_arg1:CopData, _arg2:int, _arg3:OfficerCell){
            super(_arg1, _arg2, _arg3);
        }
        override protected function makeActionPanel():JPanel{
            var _local5:TextFormat;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -5);
            var _local2:Number = this.getTimeLeft();
            if (_local2 <= 0){
                this.changeState();
            } else {
                m_timeLeft = ASwingHelper.makeTextField(GameUtil.formatMinutesSeconds(_local2), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.blueTextColor);
                m_nextActiveTimer = new Timer(958);
                m_nextActiveTimer.addEventListener(TimerEvent.TIMER, updateTimerString);
                m_nextActiveTimer.start();
                _local5 = m_timeLeft.getTextFormat();
                _local5.align = TextFormatAlign.RIGHT;
                m_timeLeft.setTextFormat(_local5);
            };
            var _local3:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "Cops_status_sleeping"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.blueTextColor, JLabel.RIGHT);
            var _local4:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "Cops_status_getdonuts"), EmbeddedArt.TITLE_FONT, 14, EmbeddedArt.blueTextColor, JLabel.RIGHT);
            _local1.appendAll(m_timeLeft, _local3, _local4);
            return (_local1);
        }
        override protected function changeState():void{
            if (((m_nextActiveTimer) && (m_nextActiveTimer.hasEventListener(TimerEvent.TIMER)))){
                m_nextActiveTimer.stop();
                m_nextActiveTimer.removeEventListener(TimerEvent.TIMER, updateTimerString);
            };
            var _local1:CopsNBanditsWorkers = (Global.copsNBanditsWorkerManager.getWorkers("cops") as CopsNBanditsWorkers);
            var _local2:CopData = _local1.getCopData(m_pos);
            _local2.setState(CopData.STATE_PATROLLING);
            _local2.setTimestamp(Math.floor((GlobalEngine.getTimer() / 1000)));
            UI.requestPatrol(null, null, m_pos);
            _local1.setCopData(_local2);
            this.rebuildEvent();
        }
        override protected function rebuildEvent():void{
            m_cell.forceRebuildCell(OfficerCell.STATE_PATROLLING, true);
        }
        override protected function getTimeLeft():Number{
            var _local1:Number = BanditManager.getCopSleepTime();
            var _local2:Number = (GlobalEngine.serverTime / 1000);
            var _local3:uint = m_officer.getTimestamp();
            var _local4:Number = (_local2 - _local3);
            var _local5:Number = (_local1 - _local4);
            return (Math.ceil((_local1 - (_local2 - _local3))));
        }

    }
}//package Display.CopsBanditsUI.OfficerCellStates 
